package com.jtjrenren.android.taxi.passenger.core.user.register;

import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.base.BaseMvpActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/1/30.
 */
public class UserRegisterActivity extends BaseMvpActivity<RegisterPresenter> implements RegisterView{
    @BindView(R.id.register_getcode)
    TextView tv_getcode;
    @BindView(R.id.register_pwd)
    EditText et_pwd;
    @BindView(R.id.register_code_input)
    EditText et_code;
    @BindView(R.id.register_phone_no)
    EditText et_phone;
    @BindView(R.id.title)
    TextView tv_title;


    @Override
    public int getLayoutId() {
        return R.layout.aty_user_register;
    }

    @Override
    public void initM() {
        tv_title.setText("注册");
        presenter.init();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.destory();
    }

    @OnClick(R.id.title_left)
    public void clickBak(){
        finish();
    }

    @OnClick(R.id.register_getcode)
    public void getYzm() {
        String phone = et_phone.getText().toString().trim();
        presenter.sendYzm(phone);
    }

    @OnClick(R.id.register_commit)
    public void commit() {
        String phone = et_phone.getText().toString().trim();
        String code = et_code.getText().toString().trim();
        String pwd = et_pwd.getText().toString().trim();
        presenter.register(phone,code,pwd);
    }

    @Override
    public void startCountDown() {
        tv_getcode.setEnabled(false);
    }

    @Override
    public void refreshCountDown(int process) {
        tv_getcode.setText(process + getString(R.string.afterrsend));
    }

    @Override
    public void downFinish() {
        tv_getcode.setEnabled(true);
        tv_getcode.setText(getString(R.string.getCode));
    }

    @Override
    public void showTip(String desc) {
        Toast.makeText(this,desc,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void finishOk(boolean isOk) {
        if (isOk)
            setResult(RESULT_OK);
        finish();
    }

    @Override
    public RegisterPresenter createPresenter() {
        return new RegisterPresenterImpl(this);
    }


}
